<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-03 11:24
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Criterias;


use Flower\Core\Repository\Contracts\CriteriaInterface;
use Flower\Core\Repository\Contracts\RepositoryInterface;

class GetPortfolioCriteria implements CriteriaInterface
{
	protected  $request;
	public function __construct($requestData)
	{
		$this->request = $requestData;
	}

	/**
	 * Apply criteria in query repository
	 *
	 * @param                     $model
	 * @param RepositoryInterface $repository
	 *
	 * @return mixed
	 */
	public function apply($model, RepositoryInterface $repository)
	{
		if($this->request['type'] == 1){
			$model = $model->where($this->request)->with(['picture' => function($query)      {
				$query->select(['id','image']);
			}]);
		}else if($this->request['type'] == 2){
			$model = $model->where($this->request)->with(['video' => function($query)      {
				$query->select(['id','url','thumb']);
			}]);
		}
		return $model;
	}

}